package com.bookcloud.java21.chapter4.类的声明对象43;

public class NewObjectTest {
  public static void main(String[] args) {
    // 创建对象
    Student s1 = new Student();
    System.out.println("s1的地址：" + s1);
    // 调用方法
    s1.setName("张三");
    s1.setAge(18);
    s1.setSex("男");
    System.out.println("s1的姓名：" + s1.getName());
    System.out.println("s1的年龄：" + s1.getAge());
    System.out.println("s1的性别：" + s1.getSex());
    s1.setAge(30);
    System.out.println("s1的年龄：" + s1.getAge());
    Student s2 = new Student();
    System.out.println("s2的地址：" + s2);
    s2.setName("李四");
    s2.setAge(20);
    s2.setSex("女");
    System.out.println("s2的姓名：" + s2.getName());
    System.out.println("s2的年龄：" + s2.getAge());
    System.out.println("s2的性别：" + s2.getSex());
    // 引用同一个对象地址
    Student s3 = s2;
    System.out.println("s3的地址：" + s3);
    System.out.println("s3的姓名：" + s3.getName());
    System.out.println("s3的年龄：" + s3.getAge());
    System.out.println("s3的性别：" + s3.getSex());
    // 修改s3的姓名
    s3.setName("王五");
    System.out.println("s3的姓名：" + s3.getName());
    System.out.println("s2的姓名：" + s2.getName());
    // 对象数组
    Student[] students = new Student[3];
    students[0] = s1;
    students[1] = s2;
    Student s4 = new Student();
    s4.setName("赵六");
    s4.setAge(30);
    s4.setSex("男");
    students[2] = s4;
    for (int i = 0; i < students.length; i++) {
      System.out.println("第" + (i + 1) + "个学生的姓名：" + students[i].getName());
    }
  }
}
